----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    14:44:53 02/24/2012 
-- Design Name: 
-- Module Name:    captador - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity captador is
    Port ( PILA_OUT : in  STD_LOGIC_VECTOR (9 downto 0);
           OFFSET : in  STD_LOGIC_VECTOR (7 downto 0);
           JUMP_ADDRESS : in  STD_LOGIC_VECTOR (9 downto 0);
           PC_IN : in  STD_LOGIC_VECTOR (9 downto 0);
           INT_RET : in  STD_LOGIC_VECTOR (9 downto 0);
           IS_BRANCH : in  STD_LOGIC;
			  BRANCHOP : in STD_LOGIC_VECTOR (1 downto 0);
           IS_RETI : in  STD_LOGIC;
           IS_SUB_RET : in  STD_LOGIC;
           IS_JUMP : in  STD_LOGIC;
           IS_INTR : in  STD_LOGIC;
           PC_NEW : out  STD_LOGIC_VECTOR (9 downto 0));
			  
end captador;

architecture Behavioral of captador is
begin

process (PILA_OUT, OFFSET, JUMP_ADDRESS, PC_IN, INT_RET, IS_BRANCH, IS_RETI, IS_SUB_RET,  IS_JUMP, IS_INTR)
--Salida del sumador a esta variable 
variable tempSumador : STD_LOGIC_VECTOR (9 downto 0);
begin
	if (IS_BRANCH = '1') then
		if (BRANCHOP = "00" OR BRANCHOP = "10") then
			tempSumador := PC_IN + OFFSET;
		elsif (BRANCHOP = "01" OR BRANCHOP = "11") then
			tempSumador := PC_IN - OFFSET;
		end if;
	else
		tempSumador := PC_IN + ext("1", 10);
	end if;
	
	if (IS_JUMP = '1') then 
		PC_NEW <= JUMP_ADDRESS;
	elsif (IS_SUB_RET = '1') then
		PC_NEW <= PILA_OUT;
	elsif (IS_RETI = '1') then
		PC_NEW <= INT_RET;
	elsif (IS_INTR = '1') then
		PC_NEW <= (others => '0');
	else
		PC_NEW <= tempSumador;
	end if;
	
end process;

end Behavioral;

